package com.zlc.study.controller;

import com.zlc.study.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.annotation.Documented;

@RestController
@Slf4j
public class RAGController {
    @Resource
    private InMemoryEmbeddingStore<TextSegment> embeddingStore;

    @Resource
    private ChatAssistant chatAssistant;

    @GetMapping(value = "/rag/add")
    public String testAdd(){
        Document document = FileSystemDocumentLoader.loadDocument("C:\\Users\\48138\\Desktop\\框架面试题精简.doc");
        EmbeddingStoreIngestor.ingest(document, embeddingStore);

        String result = chatAssistant.chat("谈谈你对AOP的理解,以及AOP的底层实现原理?");

        System.out.println(result);
        return result;

    }
}
